package com.springinaction.ch02;

import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.SystemOutRule;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.junit.Assert.*;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration //可以不写配置context但是要新建一个文件 类名-context.xml
//@ContextConfiguration("classpath:com/springinaction/ch02/cdPlayConfig.xml")
//@ContextConfiguration(classes = com.springinaction.ch02.CdPlayConfig.class)
public class CDPlayerTest {
    @Rule
    public final SystemOutRule log=new SystemOutRule().enableLog();
    @Autowired
    private CompactDisc cd;

    @Autowired MediaPlayer mediaPlayer;
    @Test
    public void cdShouldNotBeNull(){
        assertNotNull(cd);
    }

    @Test
    public void testPlay(){
        mediaPlayer.play();
        assertEquals("Playing Sgt. Pepper's Lonely Hearts Club Band by The Beatles\r\n",log.getLog());
    }

}
